//
//  HOExtraAssistantEntity.m
//  WeiDu
//
//  Created by foguo-mac-1 on 27/12/2017.
//  Copyright © 2017 WeiDu. All rights reserved.
//

#import "HOExtraAssistantEntity.h"
#import "HOUtils.h"
#import "HOConstants.h"
#import "HOAreaEntity.h"
#import "HOStaticDataMgr.h"

@implementation HOExtraAssistantEntity

- (id)init
{
	if(self = [super init])
	{
		self.faultAreaName = [NSMutableString string];
	}
	return self;
}

- (void)parseDic:(NSDictionary *)dic
{
	[super parseDic:dic];
	
//	@property(nonatomic, retain)NSString *budget;
//	@property(nonatomic, retain)NSString *extraMobile; //外协手机
//	@property(nonatomic, retain)NSString *extraName;  //外协公司名字
//	@property(nonatomic, retain)NSString *faultDetail; //故障详情
//	@property(nonatomic, retain)NSString *faultAddress;//故障地点
//	@property(nonatomic, retain)NSString *effectScope;//影响范围
//	@property(nonatomic, retain)NSString *FixTime;//建议修复时间
	self.budget = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Budget]];
	self.extraMobile = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_ExternalMobile]];
	self.extraName = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_ExternalCompany]];
	self.faultDetail = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_FaultDetail]];
	self.faultAddress = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_FaultAddress]];
	self.effectScope = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Incidence]];
	self.fixTime = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_ProposalTime]] integerValue];
	self.trueName = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_TrueName]];
	self.telephone = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Telephone]];
	self.departmentName = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_DepartmentName]];
	
	self.companyId = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_CompanyID]];
	self.status = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_Status]] intValue];
	self.postId = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_PostId]] intValue];
//	self.directorId = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_DirectorId]] intValue];
//	if(self.directorId == 0)
	self.directorId = [[HOStaticDataMgr sharedInstance] getDirectorId];
	self.deanId = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_DeanId]] intValue];
	
	[self parseAreas:dic];
}

- (void)parseAreas:(NSDictionary *)dic
{
	if(dic == nil)
		return;
	self.faultAreaName = [NSMutableString string];
	NSArray *areaList = [dic objectForKey:kHO_FIELD_FaultArea];
	if(areaList != nil && areaList.count > 0)
	{
		for(int i = 0; i < [areaList count]; i ++)
		{
			NSDictionary *areaDic = [areaList objectAtIndex:i];
			int areaId = [[HOUtils getValideString:[areaDic objectForKey:kHO_FIELD_AreaId]] intValue];
			NSString *areaName = [HOUtils getValideString:[areaDic objectForKey:kHO_FIELD_AreaName]];
			if(areaId == 0 || areaName == nil || areaName.length == 0)
				continue;
			HOAreaEntity *areaEntity = [[HOStaticDataMgr sharedInstance] getAreaEntityWithId:areaId];
			if(!areaEntity)
			{
				continue;
			}
			areaEntity.areaName = areaName;
			[self.faultAreaList addObject:areaEntity];
			if(self.faultAreaName.length > 0)
			{
				[self.faultAreaName appendFormat:@"-%@", areaName];
			}
			else
			{
				[self.faultAreaName appendFormat:@"%@", areaName];
			}
			if(i == 0)
				self.firstAreaEntity = areaEntity;
			else if(i == 1)
				self.secondAreaEntity = areaEntity;
			else if(i == 2)
				self.thirdAreaEntity = areaEntity;
		}
	}
	self.faultAddress = self.faultAreaName;
}

- (NSString *)getStatusString
{
	NSString *statusStr = [HOUtils getDescribtionWithStatus:self.status];
	/*
	 HO_EXTRA_ASS_ORDER_DELETED 		= 18,   //删除的外协单
	 HO_EXTRA_ASS_ORDER_ALL 			= 19,   //所有外协单
	 HO_EXTRA_ASS_ORDER_UNCHECK 		= 20,   //未审核
	 HO_EXTRA_ASS_ORDER_DIR_CHECK 	= 21, 	//一级审核  主任审核
	 HO_EXTRA_ASS_ORDER_DEAN_CHECK 	= 22, 	//二级审核  院长审核
	 HO_EXTRA_ASS_ORDER_REPAIRED 	= 23,	//维修完成
	 HO_EXTRA_ASS_ORDER_CONFIRMED 	= 24, 	//确认完成
	 HO_EXTRA_ASS_ORDER_CHECK_FAILED = 25, 	//审核失败
	 HO_EXTRA_ASS_ORDER_CHECK_UNCOMPLETE = 26, 	//未维修完成
	 */
	if(self.status == HO_EXTRA_ASS_ORDER_DIR_CHECK && self.deanId >0)
	{
		return @"主任已审核,院长未审核";
	}
	else if(self.status == HO_EXTRA_ASS_ORDER_DIR_CHECK && self.deanId == 0)
	{
		return @"主任已审核(审核完毕)";
	}
	else if(self.status == HO_EXTRA_ASS_ORDER_DEAN_CHECK)
	{
		return @"院长已审核(审核完毕)";
	}
	return statusStr;
}

- (BOOL)notNeedDeanCheck
{
	return (self.status >= HO_EXTRA_ASS_ORDER_DIR_CHECK && self.deanId == 0);
}

- (NSString *)getFaultDetailContent
{
	NSString *content = [HOUtils getValideString:self.faultDetail];
	if([self.detail isEqualToString:@"无"])
	{
		BOOL isPictureDetail = (self.image && self.image.length > 0 );
		BOOL isAudioDetail = (self.voice && self.voice.length > 0);
		if(isPictureDetail && isAudioDetail)
		{
			content = [NSString stringWithFormat:@"%@", @"[图片] + [语音]"];
		}
		else if(isPictureDetail)
		{
			content = [NSString stringWithFormat:@"%@", @"[图片]"];
		}
		else if(isAudioDetail)
		{
			content = [NSString stringWithFormat:@"%@", @"[语音]"];
		}
	}
	return content;
}
@end
